#include<bits/stdc++.h>
using namespace std;
struct node{
	int st;
	double v0,a,stcs,edcs;
	bool sfcs,sfzd;
}car[200005];
int num,n,m,l,qk[200005],mn=200005;
bool vis[200005],viss[200005];
vector<int> cqk[200005];
double lmt;
int upp(double x){
	return int(x+1);
}
int doo(double x){
	return int(x-1);
}
void work1(){
	for(int i=1;i<=n;i++){
		cin>>car[i].st>>car[i].v0>>car[i].a;
		if(car[i].a==0){
			if(car[i].v0>lmt) car[i].sfcs=1,car[i].stcs=car[i].st,car[i].edcs=l;
			else car[i].sfcs=0;
		}
		else{
			if(car[i].a<0){
				car[i].a*=-1;
				if(car[i].v0<=lmt) car[i].sfcs=0;
				else car[i].sfcs=1,car[i].stcs=car[i].st,car[i].edcs=min(l,car[i].st+doo((car[i].v0*1.0*car[i].v0-lmt*1.0*lmt)/2.0/car[i].a));
			}
			else{
				if(car[i].v0>lmt) car[i].sfcs=1,car[i].stcs=car[i].st,car[i].edcs=l;
				else if(car[i].v0==lmt) car[i].sfcs=1,car[i].stcs=car[i].st+1,car[i].edcs=l;
				else {
					if(car[i].st+upp((lmt*1.0*lmt-car[i].v0*1.0*car[i].v0)/2.0/car[i].a)>=l) car[i].sfcs=0;
					else{
						car[i].sfcs=1,car[i].stcs=car[i].st+upp((lmt*1.0*lmt-car[i].v0*1.0*car[i].v0)/2.0/car[i].a),car[i].edcs=l;
					}
				}
			}
		}
	}
	for(int i=1;i<=m;i++){
		cin>>qk[i];
	}
	for(int i=1;i<=n;i++){
		car[i].sfzd=0;
		if(car[i].sfcs){
			//cout<<i<<' '<<car[i].stcs<<' '<<car[i].edcs<<endl;
			int lb=lower_bound(qk+1,qk+m+1,car[i].stcs)-qk;
			if(lb!=m+1&&qk[lb]<=car[i].edcs) {
				car[i].sfzd=1;
				num++;
				for(int j=lb;j<=m;j++)
					if(qk[j]<=car[i].edcs)
						cqk[j].push_back(i);
			}
		}
	}
	//for(int i=1;i<=m;i++){
		//for(auto x:cqk[i]){
		//	cout<<x<<' ';
		//}
		//cout<<endl;
	//}
}
void dfs(int i,int cnt,bool vis[]){
	if(i==n+1) return ;
	int fl=1;
	//cout<<i<<endl<<cnt<<endl;
	for(int i=1;i<=n;i++){
		//cout<<vis[i]<<' ';
		if((!vis[i])&&car[i].sfzd) fl=0;
	}
	//cout<<endl;
	if(fl) mn=min(mn,cnt);
	dfs(i+1,cnt,vis);
	for(int i=1;i<=n;i++){
		viss[i]=vis[i];
	}
	for(auto x:cqk[i]){
		viss[x]=1;
	}
	dfs(i+1,cnt+1,viss);
}
void work2(){
	for(int i=1;i<=n;i++){
		vis[i]=0;
	}
	dfs(1,0,vis);
	for(auto x:cqk[1]){
		vis[x]=1;
	}
	dfs(1,1,vis);
}
void solve(){
	cin>>n>>m>>l>>lmt;
	if(n*m<=100000000){
		work1();
		cout<<num<<' ';
		work2();
		cout<<m-mn<<endl;
	}
	else{
		work1();
		cout<<num<<' ';
		work2();
		cout<<m-mn<<endl;
	}
}
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int t;cin>>t;
	while(t--){
		solve();
	}
}
